#  rest_framework
from rest_framework import serializers

#  导入数据模型
from django.contrib.auth.models import User
from oauth2_provider.models import (
    Application, AccessToken, RefreshToken, Grant,
)

class AppSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Application
        fields = (
                    'url',
                    'id',
                    'client_id',
                    'user_id',
                    'redirect_uris',
                    'client_type',
                    'authorization_grant_type',
                    'client_secret',
                    'name',
                    'skip_authorization',
                    'created',
                    'updated',
                )

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = (
                    'url',
                    'id',
                    'password',
                    'last_login',
                    'is_superuser',
                    'username',
                    'first_name',
                    'last_name',
                    'email',
                    'is_staff',
                    'is_active',
                    'date_joined',
                )

class SignUpSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = User
        fields = ('username', 'password')
        write_only_fields = ('password')
